import { Color4, FloatArray, Mesh, MeshBuilder, Scene } from "@babylonjs/core";

export const WHITE: Color4 = new Color4(1, 1, 1, 1);
export const RED: Color4 = new Color4(1, 0, 0, 1);
export const GREEN: Color4 = new Color4(0, 1, 0, 1);
export const BLUE: Color4 = new Color4(0, 0, 1, 1);

export function createProbe(name: string, color: Color4, scene: Scene): Mesh {
    let faceColors = []
    for (let i = 0; i < 6; ++i) {
        faceColors.push(color)
    }
    const ret = MeshBuilder.CreateBox(name, {size: 1, faceColors, updatable: true}, scene)

    ret.updateMeshPositions((arr: FloatArray) => {
        const count = arr.length / 3;
        for (let i = 0; i < count; ++i) {
            const idx = i * 3;
            arr[idx + 2] += 0.5;
            arr[idx + 2] *= 2.4;
            arr[idx] *= 0.5
            arr[idx + 1] *= 0.5

            if (arr[idx + 1] > 0) {
                arr[idx + 0] *= 0.6
            }
        }
    })

    return ret
}